import { createSlice } from '@reduxjs/toolkit'

const count = createSlice({
	name: 'count',
	initialState: {
		value: 0,
	},
	reducers: {
		increment: (state, action) => {
			state.value += action.payload
		},
		decrement: (state, action) => {
			state.value -= action.payload
		},
		oddIncrement: (state, action) => {
			state.value += action.payload
		},
	},
})

export const asyncIncrement = (data, time) => dispatch => {
	setTimeout(() => dispatch(increment(data)), time)
}

export default count.reducer
export const { increment, decrement, oddIncrement } = count.actions
